<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
      <title>提现</title>
      <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
      <style>
          body{
            width: 100%;

          }
          .top{
          	width:100%;
          	height: 40px;
          	margin: 40px auto 0px;
          	background: #f5f5f5;
          	color:#000;
          	border:0px;
          	display: block;
          	text-align: center;
          }
          .leftreturn{
            position: absolute;
            left:0;
            z-index: 5;
            background-image: url("../../image/leftreturn.png");
            background-position: 0px 0px;
            width:25px;
            height:25px;
            margin:7.5px 0;
          }
          .top-title{
            line-height: 40px;
            font-size: 20px;
          }

          .mui-input-row{
            width: 100%;
            padding: 10px;
            font-size: 18px;
          }
          .icon{
            position: absolute;
            left:20px;
            z-index: 5;
            background-image: url(../../image/money_icon.png);
            background-repeat: no-repeat;
            background-position: 0px 0px;
            width:30px;
            height:30px;
          }
          .capital{
              width:100%;
              padding-left:45px;
              border-bottom: 1px solid #f5f5f5;
              outline: none;
              font-size: 28px;
          }
          label{
            padding: 10px;
          }
          .czways{
            width:100%;
            padding: 10px;
            height:30px;
          }
          .ways{
            width:100px;
            height:30px;
            line-height: 30px;
            font-size: 16px;
          }
          .select3{
            border: none;
            width: 200px;
            height:30px;
            line-height: 30px;
            font-size: 16px;
            color: #aaa;
            outline: none;
            -webkit-appearance:none;
            -moz-appearance:none;
            appearance:none;
          }
          .footer{
            position: absolute;
            bottom: 0;
            width: 100%;
          }
          .footer p{
            text-align: center;
            padding: 20px;
          }
          .btn{
            border: 1px solid #f5f5f5;
            background-color: #bfbfbf;
            border-radius: 8px;
            width:150px;
            height:40px;
            color: #707070;
          }
          .dqye{
            font-size: 14px;
            color: #888;
            padding-left: 45px;
            padding-top: 5px;
          }
      </style>
  </head>
  <body>
    <div class="top">
      <i class="leftreturn" onclick="returnframe3();"></i>
      <h1 class="top-title">提现</h1>
    </div>
    <div class="czways">
      <span class="ways">到账</span>
      <select class="select3" name="czType" id="goodsType">
        <option>请选择</option>
        <option>微信到账</option>
        <option>支付宝到账</option>
        <option>银联到账</option>
      </select>
    </div>
    <label>提现金额</label>
    <div class="mui-input-row">
      <i class="icon"></i>
      <input type="tel" class="capital mui-input-clear" value="0.00" id="money">
      <p class="dqye">当前余额</p>
    </div>
    <div class="footer">
      <p><input type="submit" value="提现" class="btn" onclick="withdraw();"/></p>
    </div>
  </body>
  <script type="text/javascript" src="../../script/SHA1.js"></script>
  <script type="text/javascript" src="../../script/api.js"></script>
  <script type="text/javascript">
      /*投资本金仅能输入数字和小数点*/
    var precapital;
    document.querySelector('.capital').addEventListener('focus', function() {
      if (this.value == '0.00') {
          this.value = '';
      } else {
          this.value = this.value.replace(/\.00/, '').replace(/(\.\d)0/,'$1');
      }
      precapital = this.value;
    });
    document.querySelector('.capital').addEventListener('keyup', function() {

      this.value = this.value.replace(/^[\.]/, '').replace(/[^\d.]/g, '');
      if (this.value.split(".").length - 1 > 1) {
          this.value = precapital;
      }
      precapital = this.value;
    });
    document.querySelector('.capital').addEventListener('blur', function() {
      this.value = this.value.replace(/[\.]$/, '');
      this.value = this.value.replace(/(.*)\.([\d]{2})(\d*)/g,'$1.$2');
      this.value = Number(this.value).toFixed(2);
      var logNum = this.value.toString();
      if(logNum.match(/\./g) != null){
          integerNum = parseInt(logNum).toString().replace(/\d(?=(\d{3})+$)/g,'$&,');
          decimalNum = '.' + logNum.replace(/(.*)\.(.*)/g,'$2');
          // document.querySelector(".logbox").innerHTML = integerNum+decimalNum;
      }else{
          // document.querySelector(".logbox").innerHTML = logNum.replace(/\d(?=(\d{3})+$)/g,'$&,');
      }
    });
  </script>
  <script type="text/javascript">
      apiready = function(){

      };


            function withdraw(){
              var money =document.getElementById('money').value;
              var goodsType=document.getElementById('goodsType').value;
              var user = $api.getStorage('user');


              var now = Date.now();
               appKey = SHA1("A6032422409194"+"UZ"+"808CF36B-60D4-DC5D-C9F3-FB49F9E1FB44"+"UZ"+now)+"."+now

              if(goodsType=='请选择'){
                alert('请选择提现方式');
              }else if(money==0){
                alert('提现数额不能为0')
              }else{
                var balance_=user[0].balance-Number(money);

                if(balance_<0){
                  alert("提现数额过大，请重新选择数额");
                }else {
                  api.ajax({
                      url: "https://d.apicloud.com/mcm/api/user/"+user[0].id,
                      method: 'post',
                      cache:  false,
                      headers:{
                        "X-APICloud-AppId": "A6032422409194",
                        "X-APICloud-AppKey": appKey
                      },
                      data:{
                        values: {
                         "balance":balance_,
                         "_method":"PUT"
                                }
                      }
                  },function(ret, err){
                      if (ret) {
                        var user = $api.getStorage('user');
                        user[0].balance=ret.balance;
                        $api.setStorage('user', user);
                          api.sendEvent({
                              name: 'updatewdye',
                              extra: {
                                  balance: ret.balance
                              }
                          });


                          api.closeWin({
                              name: api.winName
                          });

                      } else {
                        alert('数据库连接失败');
                  }
                  });
                }
              }
        }

      function returnframe3() {
        api.closeWin();
        }
  </script>
  </html>
